
package time.basic.axis;

import java.text.DecimalFormat;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.time.Month;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

/**
 * change value axis format<br>
 * 
 * @author Eric.Kao(gau168.gau@msa.hinet.net)
 * @version 1.0
 * @company E885 Group
 * @copyright Copyright (c) 2001-2008
 */

public class ChangeValueAxisFormat
{
	private String housePriceLengendLabel = "房價指數";

	private String title = "房價指數圖";

	private String timeAxisLabel = "估價日期";

	private String valueAxisLabel = "總價(萬元)";

	public ChangeValueAxisFormat()
	{
		JFreeChart chart = createTimeSeriesChart();

		XYPlot plot = ( XYPlot )chart.getPlot();

		ValueAxis valueAxis = plot.getRangeAxis();

		NumberAxis numberAxis = ( NumberAxis )valueAxis;

		numberAxis.setNumberFormatOverride( new DecimalFormat( "##########.00" ) );

		display( chart );
	}

	/**
	 * @param args
	 */
	public static void main( String[] args )
	{
		new ChangeValueAxisFormat();
	}

	private JFreeChart createTimeSeriesChart()
	{
		TimeSeries housePriceTS = new TimeSeries( housePriceLengendLabel, Month.class );
		housePriceTS.add( new Month( 2, 2001 ), 181.82343 );
//		housePriceTS.add( new Month( 3, 2001 ), 185.82343 );

		TimeSeriesCollection dataset = new TimeSeriesCollection();
		dataset.addSeries( housePriceTS );

		return ChartFactory.createTimeSeriesChart( title, timeAxisLabel, valueAxisLabel, dataset, true, true, false );
	}

	private void display( JFreeChart chart )
	{
		ChartFrame frame = new ChartFrame( "Test", chart );
		frame.pack();
		frame.setVisible( true );
	}
}
